package com.gkd.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gkd.mapper.EmployeeMapper;
import com.gkd.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService{
    @Autowired
    EmployeeMapper employeeMapper;
//    @Autowired
//    private DepartmentDao departmentDao;

    @Override
    public PageInfo<Employee> queryAllPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Employee> someEmployees = employeeMapper.queryPageAll();//调用 业务逻辑对数据dao的访问
//        for(int i=0;i<someEmployees.size();i++){
//            someEmployees.get(i).setDepartment(departmentDao.fdm.get(i));
//        }
        PageInfo<Employee> userPageInfo= new PageInfo<Employee>(someEmployees,pageSize);
        return userPageInfo;
    }

    @Override
    public List<Employee> queryEmployeeAll() {
        return employeeMapper.queryEmployeeAll();
    }

    @Override
    public Employee selectEmployeeById(int id) {
        return employeeMapper.selectEmployeeById(id);
    }

    @Override
    public void removeEmployeeById(int id) {
        employeeMapper.deleteEmployee(id);
    }

    @Override
    public void addEmployee(Employee employee) {
        employeeMapper.insertEmployee(employee);
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeMapper.updateEmployeeById(employee);
    }

    @Override
    public List<Integer> queryEmployeeAllID() {
        return employeeMapper.selectEmployeeForId();
    }

    @Override
    public Map<Integer, Boolean> checklistById() {
        Map<Integer,Boolean> cid = new HashMap<>();
        List<Integer> list = queryEmployeeAllID();
        for (int i=0;i<list.size();i++){
            cid.put(list.get(i),false);
        }
        return cid;
    }

}
